//
//  ChangePasswordVC.m
//  liBaQiang
//
//  Created by 奇林刘 on 2018/11/12.
//  Copyright © 2018年 liu. All rights reserved.
//

#import "ChangePasswordVC.h"
#import "ChangePasswordVCRegularField.h"

@interface ChangePasswordVC ()
@property (strong, nonatomic) ChangePasswordVCRegularField *passwordField;
@property (strong, nonatomic) ChangePasswordVCRegularField *checkField;
@property (weak, nonatomic) IBOutlet UIButton *submitButton;

@end

@implementation ChangePasswordVC {
    NSString *_resetToken;
}

- (instancetype)initWithResetToken:(NSString *)resetToken {
    _resetToken = resetToken;
    self = [super init];
    return self;
}

- (void)allocateComponents {
    self.view.fp_addSubview(self.passwordField = [[ChangePasswordVCRegularField alloc] initWithName:@"新密码" placeholder:@"请输入新密码"]);
    self.view.fp_addSubview(self.checkField = [[ChangePasswordVCRegularField alloc] initWithName:@"确认新密码" placeholder:@"请确认两次密码一致"]);
}

- (void)layoutComponents {
    [self.passwordField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(RPX(15));
    }];
    [self.checkField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passwordField.mas_bottom).offset(RPX(11));
    }];
    [self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.checkField.mas_bottom).offset(RPX(20));
        make.width.equalTo(@(RPX(345)));
        make.height.equalTo(@(RPX(44)));
    }];
}

- (void)configComponents {
    [self.submitButton setTitle:@"提交" forState:UIControlStateNormal];
    self.submitButton.fp_cornerRadius(RPX(4)).fp_backgroundColor(HexadecimalColor(@"#2D5898"));
    self.submitButton.titleLabel.font = RPXFont(16);
    [self.submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}

- (IBAction)onSubmitButtonTap:(id)sender {
    if (![self.passwordField.field.text isEqualToString:self.checkField.field.text]) {
        [SVProgressHUD showInfoWithStatus:@"两次密码不一致！"];
        return;
    }
    [LBQRequestMobileLoginResetpwd goRequestWithResetToken:_resetToken
                                                  password:self.passwordField.field.text
                                               device_type:DeviceType
                                                   success:^(NSURLSessionDataTask *task, id  _Nullable responseObject) {
                                                       [HandyMethods dispatchAfter:0.5 do:^{
                                                           [self dismissViewControllerAnimated:YES completion:nil];
                                                       }];
                                                   }
                                                   failure:^(NSURLSessionDataTask *task, id  _Nullable responseObject) {
                                                       
                                                   }];
}



@end
